package com.winz.cultureapp.activity;

import android.content.Intent;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.winz.cultureapp.R;
import com.winz.cultureapp.base.BaseAppCompatActivity;
import com.winz.cultureapp.constants.Constants;
import com.winz.cultureapp.entity.ArtDesBean;
import com.winz.cultureapp.http.OnResponeListener;
import com.winz.cultureapp.http.util.HttpUitls;
import com.winz.cultureapp.utils.JsonUtil;
import com.winz.cultureapp.utils.Logger;

import butterknife.BindView;
import butterknife.OnClick;
import cn.jzvd.JzvdStd;

public class ArtDesVideoActivity extends BaseAppCompatActivity {
    @BindView(R.id.tv_top_title)
    TextView mTv_top_title;
    @BindView(R.id.videoplayer)
    JzvdStd videoplayer;
    @BindView(R.id.tv_content)
    TextView mTv_content;

    private String artId;

    @Override
    protected int contentView() {
        return R.layout.activity_art_des_video;
    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void loadDatas(Intent intent) {
        if (intent != null) {
            if (intent.getExtras() != null) {
                artId = intent.getExtras().getString(Constants.KEY.ART.ITEM_DES_ID);
                getList();
            }
        }
    }

    private void getList() {
        showProgressDialog();
        HttpUitls.onGet("art_detail", artId, new OnResponeListener<ArtDesBean>() {
            @Override
            public void onSuccess(ArtDesBean bean) {
                Logger.d("art_detail==>>", JsonUtil.getJsonFromObj(bean));
                if (bean.code == 0) {
                    mTv_top_title.setText(bean.data.title);
                    videoplayer.setUp(bean.data.contentUrl
                            , bean.data.title, videoplayer.SCREEN_WINDOW_NORMAL);
                    Glide.with(context)
                            .load(bean.data.imageUrl)
                            .error(R.drawable.pic_default)
                            .into(videoplayer.thumbImageView);
                    mTv_content.setText(bean.data.description);

                } else {
                    showMsg(bean.msg);
                }
                dismissProgressDialog();
            }

            @Override
            public void onFailed(String error) {
                dismissProgressDialog();
                Logger.d("art_detail==>>", error);

            }
        });
    }

    @Override
    public void onBackPressed() {
        if (videoplayer.backPress()) {
            return;
        }
        super.onBackPressed();
    }

    @Override
    protected void onPause() {
        super.onPause();
        videoplayer.releaseAllVideos();
    }

    @OnClick(R.id.fl_back)
    public void onClick() {
        finish();
    }
}
